package ij.umasuo.AOTFController;

import ij.umasuo.MyConstants;
import ij.umasuo.MyUserSettings;

public class EPICtr {
	
	private boolean isLaserOn = false;//this use to show whether we have turn on the laser
	private AOTFClient aotfClient = AOTFClient.getInstance();
	private static EPICtr instance = new EPICtr();
	
	private EPICtr(){}
	
	
	/**
	 * refresh the laser ,be called in laser,this can only be called when the lasers have been power on
	 */
	public void refreshLaser(){
		if(!isLaserOn){
			return;//only when the lasers have been turn on, we need to refresh the laser
		}
		//here we write the commands to the aotfController
		for(int i=0;i<MyUserSettings.epiLasers.size();i++){
			aotfClient.Write("dds a " +MyConstants.laserID.get(MyUserSettings.epiLasers.get(i)) +" " +MyUserSettings.epiLaserInt.get(i) +  "\r");
		}
	}

	/**
	 * get the instance
	 * @return
	 */
	public static EPICtr getInstance(){
		if(instance == null){
			instance = new EPICtr();
		}
		return instance;
	}
	
	/**
	 * power off the lasers
	 */
	public void stop(){
		isLaserOn = false;
		aotfClient.resetAOTF();
	}
	/**
	 * power on the lasers
	 */
	public void start(){
		isLaserOn = true;
		aotfClient.resetAOTF();
		// here we write the commands to the aotfController
		for (int i = 0; i < MyUserSettings.epiLasers.size(); i++) {
			aotfClient.Write("dds a " + MyConstants.laserID.get(MyUserSettings.epiLasers.get(i)) + " " + MyUserSettings.epiLaserInt.get(i) + "\r");
		}
	}
}
